Skip to content

fix(monitor): use IsValidUUID to skip uninitialised device UUIDs in scrape path - #2465

Merged
hami-robot[bot] merged 1 commit into
Project-HAMi:masterfrom
Nakshatra480:fix/use-isvaliduuid-in-scrape-path
Aug 11, 2026
Merged

fix(monitor): use IsValidUUID to skip uninitialised device UUIDs in scrape path#2465
hami-robot[bot] merged 1 commit into
Project-HAMi:masterfrom
Nakshatra480:fix/use-isvaliduuid-in-scrape-path

Conversation

@Nakshatra480

@Nakshatra480 Nakshatra480 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

collectContainerMetrics guarded against uninitialized device UUIDs with
len(uuid) < 40. This check is dead code: DeviceUUID() returns
string(s.sr.uuids[i].uuid[:]) where uuid is [96]byte, so len is
always 96 and the condition never fires.

The consequence: a container that is starting up, whose UUID slot has not yet
been written by libvgpu, passes through the guard with 40 null bytes emitted
as a Prometheus device_uuid label value instead of being skipped.

IsValidUUID(i) already exists in the UsageInfo interface and checks
uuid[0] != 0 - the correct "has libvgpu written this slot?" test. It is
already used this way in feedback.go (line 86). This PR applies the same
pattern to the scrape path.

Changes:

  • cmd/vGPUmonitor/metrics.go: replace len(uuid) < 40 with
    !c.Info.IsValidUUID(i); move the check before DeviceUUID to match
    feedback.go and avoid a string allocation on uninitialized slots;
    collapse uuid := c.Info.DeviceUUID(i)[0:40] into one statement
  • cmd/vGPUmonitor/feedback_test.go: update stubInfo.IsValidUUID from
    i < len(s.uuids) (always true within the loop) to check uuid[0] != 0,
    matching the real implementation
  • cmd/vGPUmonitor/metrics_container_test.go: replace the "short UUID" test
    case (tests a scenario that cannot occur in production since DeviceUUID
    always returns 96 bytes) with an uninitialized-UUID case (null first byte)
    that actually exercises the guard

Which issue(s) this PR fixes:
Part of #2126 (LFX observability hardening - Prometheus metric label correctness)

Special notes for your reviewer:
PR #2364 changed returncontinue for this check, but the check itself
was always unreachable. This PR makes the guard fire for the case it was
written for. The utf8.ValidString check underneath is left unchanged.

Does this PR introduce a user-facing change?
Yes containers in the startup phase no longer emit metrics with null-byte
device_uuid labels; those device slots are silently skipped until libvgpu
writes a valid UUID.

AI Disclosure:
AI assistance was used for code inspection and draft formatting; all logic,
test cases, and verification were manually reviewed and validated.

Summary by CodeRabbit

  • Bug Fixes
    • Improved device UUID validation to ignore uninitialized or invalid device entries.
    • Prevented malformed UUID data from generating incorrect container metrics.
    • Ensured valid UUID values are safely handled and limited to the supported length.
    • Added safeguards for invalid text encoding in device identifiers.
    • Updated monitoring behavior so invalid device data is skipped without producing errors.
    • Confirmed that skipped invalid entries do not create misleading or incomplete monitoring results.

@hami-robot
hami-robot Bot requested a review from FouoF August 8, 2026 06:52
@hami-robot
hami-robot Bot requested a review from ouyangluwei163 August 8, 2026 06:52
@github-actions github-actions Bot added the kind/bug Something isn't working label Aug 8, 2026
@hami-robot hami-robot Bot added the size/S label Aug 8, 2026
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 76bfc7c1-e45f-48b8-95fe-ac80de764e43

📥 Commits

Reviewing files that changed from the base of the PR and between 3adf9b0 and 07210ff.

📒 Files selected for processing (1)
  • cmd/vGPUmonitor/feedback_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/vGPUmonitor/feedback_test.go

📝 Walkthrough

Walkthrough

The change strengthens UUID validation for vGPU devices. Container metric collection skips uninitialized UUIDs, truncates valid UUIDs to 40 characters, and rejects invalid UTF-8. Tests now cover zero-filled UUIDs.

Changes

UUID validation and metrics

Layer / File(s) Summary
Validate device UUIDs during metric collection
cmd/vGPUmonitor/feedback_test.go, cmd/vGPUmonitor/metrics.go, cmd/vGPUmonitor/metrics_container_test.go
IsValidUUID rejects invalid indexes, empty UUIDs, and zero-prefixed UUIDs. Metric collection skips invalid devices, truncates valid UUIDs to 40 characters, and validates UTF-8. Tests cover uninitialized UUIDs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: ouyangluwei163, fouof

Poem

A rabbit checks each UUID with care,
Zero-filled devices leave no trace there.
Valid strings hop, trimmed and bright,
Bad UTF-8 stays out of sight.
Metrics collect through the night.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: using IsValidUUID to skip uninitialized device UUIDs during monitor scraping.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/vGPUmonitor/feedback_test.go`:
- Around line 67-69: Update stubInfo.IsValidUUID to validate that i is
non-negative before evaluating len(s.uuids[i]) or accessing s.uuids[i], while
preserving the existing bounds and UUID-content checks for valid indexes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 113379ac-1839-4c84-a79f-02221f1e33ce

📥 Commits

Reviewing files that changed from the base of the PR and between 3616313 and 3adf9b0.

📒 Files selected for processing (3)
  • cmd/vGPUmonitor/feedback_test.go
  • cmd/vGPUmonitor/metrics.go
  • cmd/vGPUmonitor/metrics_container_test.go

Comment thread cmd/vGPUmonitor/feedback_test.go
…crape path

DeviceUUID always returns a 96-byte string (from [96]byte), so the prior
guard len(uuid) < 40 could never fire. Containers starting up whose UUID
has not yet been written by libvgpu passed through with 40 null bytes
emitted as a Prometheus label value.

Replace the dead length check with IsValidUUID, which tests uuid[0] != 0
and correctly detects uninitialized slots. Update stubInfo.IsValidUUID in
the test helper to match the same semantics, and replace the short-UUID
test case with an uninitialized-UUID case that reflects the real scenario.

Signed-off-by: Nakshatra Sharma <nakshatra.sharma3012@gmail.com>
@Nakshatra480
Nakshatra480 force-pushed the fix/use-isvaliduuid-in-scrape-path branch from 3adf9b0 to 07210ff Compare August 8, 2026 06:59
@hami-robot hami-robot Bot added size/M and removed size/S labels Aug 8, 2026
@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 64.24% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/vGPUmonitor/metrics.go 43.29% <100.00%> (-0.20%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mesutoezdil

Copy link
Copy Markdown
Contributor

/lgtm

@FouoF

FouoF commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

/lgtm

@hami-robot

hami-robot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FouoF, Nakshatra480

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hami-robot hami-robot Bot added the approved label Aug 11, 2026
@hami-robot
hami-robot Bot merged commit d0dab9a into Project-HAMi:master Aug 11, 2026
17 checks passed
@Nakshatra480

Copy link
Copy Markdown
Contributor Author

@FouoF Thanks for merging this pr 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants